package com.koron.css2.meterService.impl;

import com.koron.css2.common.dto.AttachmentDto;
import com.koron.css2.common.service.AbstractExportExcel;
import com.koron.css2.meterService.bean.query.MsChgPlanQueryBean;
import com.koron.css2.meterService.dto.MsChgPlanDetailDto;
import com.koron.css2.meterService.mapper.MsChgPlanDetailMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 换表回填模板下载
 * @author 周利斌
 *
 */
public class MsChgDownload extends AbstractExportExcel{

	@Override
	public AttachmentDto getAttachment(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MsChgPlanQueryBean bean = JsonUtils.objectToPojo(req.getData(), MsChgPlanQueryBean.class);
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		if(StringUtils.isNotBlank(bean.getId())) {
			MsChgPlanDetailMapper detailMapper = factory.getMapper(MsChgPlanDetailMapper.class);
			List<MsChgPlanDetailDto> msChgPlanDetails = detailMapper.selectByReceiptId(bean.getId());
			for(MsChgPlanDetailDto detail : msChgPlanDetails) {
				Map<String, String> map = new HashMap<String, String>();
				map.put("userNo", detail.getUserNo());
				map.put("oldMeterNo", detail.getOldMeterNo());
				map.put("replaceDate", "");
				map.put("oldMeterNum", "");
				map.put("newMeterNo", "");
				map.put("newMeterNum","");
				map.put("oldHandleWay", "");
				map.put("replaceStaffName", "");
				map.put("mark", "");
				data.add(map);
			}
		}
		AttachmentDto attachemnt = new AttachmentDto();
		attachemnt.setBtlTemplate("MsChgDownload.btl");
		attachemnt.setFilename(1 == bean.getReceiptType() ? "换表回填导入模板" : "拆表回填导入模板");
		attachemnt.setFileTemplate("MsChgDownload.xlsx");
		attachemnt.setData(data);
		attachemnt.setFileType("excel");
		return attachemnt;
	}

}
